<template>
  <!-- 辅助检查内容详情 -->
  <section>
    <h3 style="text-align:center;">
      <span>{{curItem.payStatusDisplay}} - {{curItem.checkCode}}</span>
      <span v-if="curItem.payStatus==1" class="success-color">（已收费）</span>
      <span v-else class="error-color">（未收费）</span>
    </h3>
    <table width="100%" border="0" style="table-layout: fixed;">
      <tr>
        <td>开单医生：{{curItem.doctorName}}</td>
        <td style="text-align:center;">开单时间：{{curItem.time}}</td>
        <td style="text-align:right;">
          <el-date-picker
            type="datetime"
            v-model="form.outTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="报告时间："
          ></el-date-picker>
        </td>
      </tr>
    </table>
    <br />
    <el-alert type="warning" :closable="false">
      <table slot="title" width="100%" border="0">
        <tr>
          <td>过敏史：</td>
          <td>
            <div v-if="guoMinArr.length==0">否认</div>
            <div v-else>
              <span
                v-for="(item,index) in guoMinArr"
                :key="index"
                style="margin-right:10px;"
              >{{item.allergens}},{{item.allergicReaction}},{{item.allergicDegree}}</span>
            </div>
          </td>
        </tr>
      </table>
    </el-alert>
    <br />
    <el-form ref="form" label-position="top" :model="form" :rules="rules">
      <el-form-item label="检查报告：">
        <div v-if="!isEditDisabled">
          <div class="gay_color">支持：png,jpg,pdf</div>
          <largeUpFile
            v-model="form.imgs"
            :limitType="fileObj.limitType"
            :fileSize="fileObj.fileSize"
            @cleckItem="onClickFile"
          ></largeUpFile>
        </div>
        <div v-else>
          <div v-for="(item,index) in form.imgs" :key="index">
            <el-link type="primary" @click="onClickFile(item)">{{item}}</el-link>
          </div>
        </div>
      </el-form-item>
      <el-form-item label="描述：">
        <el-input
          type="textarea"
          :disabled="isEditDisabled"
          v-model="form.describe"
          :rows="3"
          placeholder="描述症状及可能存在的病情等..."
        ></el-input>
      </el-form-item>
      <el-form-item label="结论：">
        <el-input
          type="textarea"
          :disabled="isEditDisabled"
          v-model="form.result"
          :rows="3"
          placeholder="描述治疗结论等..."
        ></el-input>
      </el-form-item>
    </el-form>
    <div class="form-tool">
      <div>
        <el-button v-if="!isEditDisabled" type="primary" :loading="btnLoading" @click="onSubmit">保存</el-button>
      </div>
      <div>
        <!-- <el-button @click="onPrint" :loading="btnLoading"> <i class="iconfont icondayin vertical-middle"></i> <span class="vertical-middle">打印辅助检查报告</span> </el-button> -->
      </div>
    </div>
  </section>
</template>
<script>
import * as dayjs from "dayjs";
export default {
  props: ["curItem", "qxBtns", "cureId", "status", "patientId","allergyList"],
  components: {
    // moreImgUpLoad: () => import("@/components/moreImgUpLoad.vue")
    largeUpFile: () => import("@/components/largeUpFile.vue")
  },
  data() {
    return {
      guoMinArr: [],
      btnLoading: false,
      form: {
        id: "",
        urls: "",
        describe: "",
        result: "",
        outTime: "",
        //==================
        imgs: []
      },
      //文件对象
      fileObj: {
        limitType: ["image/png", "image/jpeg", "application/pdf"],
        fileSize: 10485760
      },
      rules: {
        imgs: [{ required: true, message: "此项必填", trigger: "change" }],
        describe: [{ required: true, message: "此项必填", trigger: "blur" }],
        result: [{ required: true, message: "此项必填", trigger: "blur" }]
      },
      isEditDisabled: true
    };
  },
  created() {
    // console.clear();
    let th = this;
    th.form = {
      id: th.curItem.id,
      urls: "",
      describe: th.curItem.describe,
      result: th.curItem.result,
      outTime: th.curItem.reportTime || "",
      //==================
      imgs: th.curItem.urls || []
    };
    let createTime = dayjs(this.curItem.time)
      .add(3, "day")
      .valueOf();
    let currentTime = dayjs().valueOf();
    if (this.status == "1") {
      if (createTime < currentTime) {
        this.isEditDisabled = true;
      } else {
        this.isEditDisabled = false;
      }
    } else {
      this.isEditDisabled = false;
    }
    this.guoMinArr=this.allergyList;
  },
  methods: {
    //点击图片
    onClickFile(file) {
      const th = this;
      if (typeof file == "string") {
        let url = th.$config.imageUrl + file;
        window.open(url);
      }
    },
    onSubmit() {
      let th = this;
      if (!th.qxBtns.addCheck) {
        th.$message.warning("权限不足");
        return;
      }
      let j = {};
      let fn = function() {
        th.btnLoading = true;
        th.$api
          .cureAssistcheckResult(j)
          .then(res => {
            if (res.executed) {
              th.$message.success("保存成功");
              th.$set(th.curItem, "isDone", true);
            } else {
              th.$message.error(res.message);
            }
            th.btnLoading = false;
          })
          .catch(res => {
            th.btnLoading = false;
          });
      };
      th.$refs["form"].validate(v => {
        if (v) {
          Object.assign(j, th.form);
          delete j.imgs;
          j.urls = JSON.stringify(th.form.imgs);
          if (!th.form.outTime) {
            th.$message.warning("请选择报告时间");
            return;
          }
          fn();
        }
      });
    },
    //获取病历
    // getDataBi() {
    //   let th = this;
    //   let j = {
    //     cureId: th.cureId
    //   };
    //   th.$api.getCureMedicalDetailId(j).then(res => {
    //     if (res.executed) {
    //       let d = res.data.curePatientAllergy;
    //       if (d && res.data.curePatientAllergy.length > 0) th.guoMinArr = d;
    //     }
    //   });
    // }
  }
};
</script>
<style lang="scss" scoped>
.moban {
  position: absolute;
  right: 0;
  top: -48px;
}
</style>
